package com.exmaple.lemlin.ui.fragment;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.TextView;

import com.exmaple.lemlin.R;
import com.exmaple.lemlin.app.APPIM;
import com.exmaple.lemlin.ui.abstracts.AbstractBaseFragment;
import com.exmaple.lemlin.ui.activity.AccessActivity;
import com.exmaple.lemlin.xmpp.XmppConnection;

import butterknife.BindView;
import butterknife.OnClick;

public class MainMineFragment extends AbstractBaseFragment {

    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_name_jid)
    TextView tvNameJid;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_main_mine;
    }

    @Override
    protected void initView() {
        tvName.setText(APPIM.getLoginUser().asBareJid().getLocalpartOrNull().intern());
        tvNameJid.setText(APPIM.getLoginUser().asBareJid().toString());
    }

    @Override
    protected void initPresenter() {

    }

    @Override
    protected void initLazyLoad() {

    }

    @OnClick({R.id.btn_exit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_exit:
                if (getActivity() == null) {
                    return;
                }
                AlertDialog dialog = new AlertDialog.Builder(getActivity())
                        .setMessage("是否退出当前账户")
                        .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                XmppConnection.getInstance().closeConnection();
                                Intent intent = new Intent(getActivity(), AccessActivity.class);
                                startActivity(intent);
                                getActivity().finish();
                            }
                        })
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        }).create();
                dialog.show();
                break;
        }
    }
}
